<%--
XPTracker - Alternative Agile Tracking Tool
Copyright (C) 2006-2009  Stephen Starkey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
--%>
<%@ include file="/taglibs.jsp" %>
<s:layout-render name="/layout/normal.jsp">
  <s:layout-component name="htmlHead">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/template.js"></script>
  </s:layout-component>
  <s:layout-component name="bodyElement"><body style="min-width:0; font-size:0.8em"></s:layout-component>
  <s:layout-component name="header">

  </s:layout-component>
  <s:layout-component name="search">

  </s:layout-component>
  <s:layout-component name="body">
    [<s:link beanclass="org.xptracker.web.EffortEntryActionBean">
       Time Clock
       <s:param name="storyId" value="${actionBean.story.id}"/>
     </s:link>]
    <s:form beanclass="org.xptracker.web.EffortEntryActionBean">
      <input type="hidden" name="storyId" value="${actionBean.story.id}"/>
      <table id="entryTable">
        <thead>
          <tr>
            <th>Start</th>
            <th>End</th>
            <th>User</th>
            <th>Comment</th>
          </tr>
        </thead>
        <tbody id="existing">
          <c:forEach items="${actionBean.story.effortEntries}" var="entry" varStatus="stat">
            <tr id="entry_${entry.id}">
              <td>
                <s:text name="story.effortEntries[${stat.index}].start"
                        formatPattern="yyyy-MM-dd HH:mm" formatType="datetime"/>
              </td>
              <td>
                <s:text name="story.effortEntries[${stat.index}].end"
                        formatPattern="yyyy-MM-dd HH:mm" formatType="datetime"/>
              </td>
              <td>
                <s:select name="story.effortEntries[${stat.index}].userId">
                  <c:forEach items="${actionBean.allUsers}" var="user">
                    <s:option value="${user.id}">${user.username}</s:option>
                  </c:forEach>
                </s:select>
              </td>
              <td>
                <s:text name="story.effortEntries[${stat.index}].comment" size="40"/>
              </td>
            </tr>
          </c:forEach>
        </tbody>
        <tbody id="rowTemplate" style="display:none">
          <tr>
            <td><input type="text" name="story.effortEntries[+{index}].start"/></td>
            <td><input type="text" name="story.effortEntries[+{index}].end"/></td>
            <td>
              <select name="story.effortEntries[+{index}].userId">
                <c:forEach items="${actionBean.allUsers}" var="user">
                  <option value="${user.id}">${user.username}</option>
                </c:forEach>
              </select>
            </td>
            <td>
              <input type="text" name="story.effortEntries[+{index}].comment" size="40"/>
            </td>
          </tr>
        </tbody>
        <tbody id="newStuff">
        </tbody>
        <tr>
          <td>
            <s:submit name="Save" value="Save" onclick="return deleteTemplate();"/>
            <s:reset name="Reset"/>
            <input type="button" value="Add" onclick="addRow()"/>
          </td>
        </tr>
      </table>
    </s:form>

    <script type="text/javascript">
      var curIndex = ${xp:size(actionBean.story.effortEntries)};

      var rowTemplate = TrimPath.parseTemplate($('rowTemplate').innerHTML)
      function addRow() {
        var result = rowTemplate.process({index: curIndex});
        new Insertion.Bottom('newStuff', result);
        curIndex++;
      }

      function deleteTemplate() {
        $('entryTable').removeChild($('rowTemplate'));
        return true;
      }
    </script>


  </s:layout-component>
</s:layout-render>